@extends("admin.base")
@section("page")
    <div class="container-fluid p-4">
        <h3>电影国籍添加页面</h3>
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body col-4">
{{--                        <form id="typesform" action="/addInfo" method="post">--}}
                        <form id="countryform">
{{--                            @csrf--}}
                            <input type="hidden" name="id" value="{{isset($country)?$country->id:0}}">
                            <div class="col-md-6 p-1">
                                <label class="form-label" for="formrow-firstname-input">中文名称</label>
                                <input type="text" name="name_ch" class="form-control" value="{{isset($country)?$country->name_ch:''}}" id="formrow-firstname-input">
                            </div>
                            <div class="col-md-6 p-1 ">
                                <div class="mb-3">
                                    <label class="form-label" for="formrow-email-input">维吾尔文名称</label>
                                    <input type="text" name="name_uy" class="form-control" value="{{isset($country)?$country->name_uy:''}}" id="formrow-email-input">
                                </div>
                            </div>
                            <div class="col-md-6 p-1">
                                <div class="mb-3">
                                    <label class="form-label" for="formrow-password-input">排序</label>
                                    <input type="number" name="order" class="form-control" value="{{isset($country)?$country->order:''}}" id="formrow-password-input">
                                </div>
                            </div>
                        </form>

                        <div class="mt-3 mb-3 p-1">
                                <button onclick="submitcountry()" class="btn btn-primary w-md"> 提交 </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>
    </div>
@endsection

@section("scripts")
    <script>
        function submitcountry(){
            var data = $("#countryform").serialize();
            // console.log(data);
            $.ajax({
                url:"countryaddinsert",    //请求的url地址
                dataType:"json",   //返回格式为json
                async:true,//请求是否异步，默认为异步，这也是ajax重要特性
                headers:{'X-CSRF-TOKEN':'{{csrf_token()}}' },
                data:data,    //参数值
                type:"POST",   //请求方式
                success:function(req){
                    if(req.err == 0){
                        swal({
                            title: "操作成功",
                            text: req.title,
                            icon: "success",
                            button: "知道了",
                        }).then((willDelete) => {
                                if (willDelete) {
                                    location.href = "/country";
                                }
                            },2000);
                    }
                },
                error:function(err){
                    //请求出错处理
                }
            });
        }
    </script>
@endsection
